package com.ewing.busi.api.pay.dto;

import java.util.Date;
import java.util.Map;
import java.util.TreeMap;

import com.ewing.core.mpsdk.WxPropertyManager;
import com.ewing.core.wxpaysdk.protocol.SignGenerator;
import com.ewing.utils.BizGenerator;
import com.google.common.collect.Maps;

/**
 * H5页面调用jsapi发起支付
 * 
 * @author chenxuegui1234@163.com
 * @createDate 2016年7月24日
 *
 */
public class JsApiPayParam {
  
  private String appId;
  
  /**
   * 时间戳
   */
  private String timeStamp;
  
  private String nonceStr;
  
  /**
   * package(由于java关键字改为pkg)订单详情扩展字符串  统一下单接口返回的prepay_id参数值，提交格式如：prepay_id=***
   */
  private String pkg;
  
  /**
   * 签名方式 签名算法，暂支持MD5
   */
  private String signType;
  
  /**
   * 签名
   */
  private String paySign;

  public JsApiPayParam(String prepayId) {
    super();
    this.appId = WxPropertyManager.getAppId();
    this.timeStamp = String.valueOf(new Date().getTime() / 1000);
    this.nonceStr = BizGenerator.generateUUID();
    this.pkg = "prepay_id="+prepayId;
    this.signType = "MD5";
    
    Map<String, Object> params = Maps.newHashMapWithExpectedSize(5);
    params.put("appId", appId);
    params.put("timeStamp", timeStamp);
    params.put("nonceStr", nonceStr);
    params.put("package", pkg);
    params.put("signType", signType);
    this.paySign = SignGenerator.createSign(new TreeMap<>(params));
  }

  public String getAppId() {
    return appId;
  }

  public void setAppId(String appId) {
    this.appId = appId;
  }

  public String getTimeStamp() {
    return timeStamp;
  }

  public void setTimeStamp(String timeStamp) {
    this.timeStamp = timeStamp;
  }

  public String getNonceStr() {
    return nonceStr;
  }

  public void setNonceStr(String nonceStr) {
    this.nonceStr = nonceStr;
  }

  public String getPkg() {
    return pkg;
  }

  public void setPkg(String pkg) {
    this.pkg = pkg;
  }

  public String getSignType() {
    return signType;
  }

  public void setSignType(String signType) {
    this.signType = signType;
  }

  public String getPaySign() {
    return paySign;
  }

  public void setPaySign(String paySign) {
    this.paySign = paySign;
  }
  
  
  
}
